<template>
  <div class="detail">
    <detail-header></detail-header>
    <detail-banner :bannerData="bannerData"></detail-banner>
    <detail-list :list="categoryList"></detail-list>
    <div class="content"></div>
  </div>
</template>

<script>
import DetailBanner from "./components/Banner";
import DetailHeader from "./components/Header";
import DetailList from "./components/List";
import axios from "axios";
export default {
  name: "Detail",
  components: {
    DetailBanner,
    DetailHeader,
    DetailList
  },
  data() {
    return {
      bannerData: {},
      categoryList: []
    };
  },
  mounted() {
    // this.getDetailInfo();
  },
  activated() {
    // 当 App.vue 设置了 keep-alive 属性时，就会有这个生命周期
    // 表示这个生命周期不受  keep-alive 属性影响，页面重新被显示时依然会执行
    this.getDetailInfo();
  },
  methods: {
    getDetailInfo() {
      axios
        .get("/api/detail.json?id=", {
          params: {
            id: this.$route.params.id
          }
        })
        .then(this.handleGetDataSucc);
    },
    handleGetDataSucc(res) {
      res = res.data;
      if (res.ret && res.data) {
        const data = res.data;
        this.bannerData = data.bannerData;
        this.categoryList = data.categoryList;
        console.log(this.bannerData);
      }
    }
  }
};
</script>
<style lang="stylus" scoped>
.content {
  height: 50rem
}
</style>
